package com.example.zhiran.service;

import com.example.zhiran.exception.OptionResultInitialException;
import com.example.zhiran.pojo.option.OptionResult;

/**
 * @author no-bald-chen
 */
public class OptionResultBuilder {

    private OptionResult optionResult;

    public OptionResultBuilder() {
        optionResult = new OptionResult();
    }

    //default
    public  OptionResult getDefault(){

        return optionResult;
    }
    /**
     *
     * @param status:状态
     * @param option:操作代码
     * @param result:结果
     * @param messageCode:提示信息代码
     * @return OptionResult
     */
    public  OptionResult setFullStateOptionResult(boolean status, int option, Object result, int messageCode ){
        optionResult = new OptionResult();
        optionResult.setStatus(status);
        optionResult.setOptionCode(option);
        optionResult.setResult(result);
        optionResult.setMessageCode(messageCode);
        return optionResult;
    }
    
    public  OptionResultBuilder setStatus(boolean status){
        optionResult.setStatus(status);
        return this;
    }

    public OptionResultBuilder setOptionCode(int optionCode) {
        optionResult.setOptionCode(optionCode);
        return this;
    }

    public OptionResultBuilder setResult(Object result){
        optionResult.setResult(result);
        return this;
    }

    public OptionResultBuilder setMessageCode(int messageCode){
        optionResult.setMessageCode(messageCode);
        return this;
    }

    public OptionResult build(){
        if (optionResult==null){
            optionResult = new OptionResult();
            return optionResult;
        }
        if (optionResult.getStatus()==null){
            optionResult.setStatus(false);
        }
        if (optionResult.getOptionCode()==null){
            optionResult.setOptionCode(OptionResult.SERVER_ERROR);
        }
        if (optionResult.getMessageCode()==null){
            optionResult.setMessageCode(OptionResult.SERVER_ERROR);
        }
        return optionResult;
    }

}
